<?

require_once("cms/core/helper/bean/Abstract.php");
require_once("cms/forum/om/TopicPeer.php");
require_once("cms/forum/om/TopicReplyPeer.php");

class PHP_CMS_View_Helper_Topics extends AbstractList {

    public function topics($form=null) {

        if($this->isInit)
            return $this;

        parent::init($form);

        $this->criteria->add(TopicPeer::CATEGORY_ID,
            $form->getId());

        $this->criteria->addJoin(
            TopicPeer::TOPIC_ID, TopicReplyPeer::TOPIC_ID, Criteria::LEFT_JOIN);

        $this->criteria->addAsColumn(
            'count', 'COUNT(' . TopicReplyPeer::TOPIC_REPLY_ID . ')');

        $this->criteria->addGroupByColumn(
            TopicReplyPeer::TOPIC_ID);

        $this->criteria->setDistinct();
        
        return $this;

    }


    /**
     * Define the propel peer we are going to use to list
     * page items.
     */
    public static function getPeer() {
        return new TopicPeer();
    }


    /**
     * Return the searchable fields for this list page.
     */
    public static function getFields() {
        return array(
            TopicPeer::NAME,
            TopicPeer::BODY,
            TopicPeer::USERNAME,
            TopicPeer::MODIFIED_DATE,
            TopicPeer::INSERT_DATE,
        );
    }
}
?>